<!-- 订单信息 START -->
<nz-card [nzSize]="cardSize" class="m-b-2">
  <nz-descriptions
    nzTitle="订单信息"
    [nzBordered]="true"
    nzSize="small"
    [nzColumn]="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }">
    <nz-descriptions-item nzTitle="订单编号">{{ orderDetailsData.okey || '-' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="订单状态">
      <span [ngStyle]="{'color': orderDetailsData.ostat | orderState: 'color'}">
        {{ orderDetailsData.ostat | orderState: 'text' }}
      </span>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="下单时间">{{ orderDetailsData.otime11 || '-' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="到货签收时间">{{ orderDetailsData.otime19 || '-' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="更新时间">{{ orderDetailsData.updateTime || '-' }}</nz-descriptions-item>
  </nz-descriptions>
</nz-card>
<!-- 订单信息 END -->

<!-- 机器评估详情 START -->
<nz-card [nzSize]="cardSize" class="m-b-2">
  <p class="card-p">机器评估详情</p>

  <div class="assess-wrap">
    <div class="assess-lf">
      <dl class="assess-info">
        <dt>
          <img
            nz-image
            width="102px"
            height="102px"
            [nzSrc]="[1, 3].includes(orderDetailsData.orderWay) ? (orderDetailsData?.umimgsrc || fallback) : batchDefaultImg"
            alt=""
          />
        </dt>
        <dd>
          <p>
            下单机型：
            <ng-container *ngIf="[1, 3].includes(orderDetailsData.orderWay);else templateXq">
              {{ orderDetailsData.umname || '-' }}
              <i
                nz-icon
                nzType="copy"
                nzTheme="outline"
                nz-tooltip
                nzTooltipTitle="点击复制"
                (click)="copyText(orderDetailsData.umname)"
              ></i>
            </ng-container>
            <ng-template #templateXq>{{ orderDetailsData.umname || '--' }}</ng-template>
          </p>
          <p *ngIf="[1, 3].includes(orderDetailsData.orderWay)">
            评估情况：
            <ng-container *ngFor="let item of situationLists">
              <nz-tag nzColor="success">
                <i nz-icon nzType="check-circle"></i>
                <span>{{ item.oname }}</span>
              </nz-tag>
            </ng-container>
            <a nz-button nzType="link" target="_blank" [routerLink]="['/aisi-recyc/assessTypeManageEdit']" [queryParams]="returnParames()">查看</a>
          </p>
        </dd>
      </dl>
    </div>

    <div class="assess-rt" *ngIf="[1, 3].includes(orderDetailsData.orderWay); else elseCjTemplate">
      <p>评估价：{{ orderDetailsData.uprc || '0' }}</p>
      <p>加价：{{ orderDetailsData.orderAprc || '0' }}</p>
      <p>下单抽奖：{{ orderDetailsData.cprc || '0' }}</p>
      <p>合计：<b>{{ (orderDetailsData.uprc || 0) + (orderDetailsData.orderAprc || 0) + (orderDetailsData.cprc || 0) }}</b></p>
    </div>
    <ng-template #elseCjTemplate>
      <div class="assess-rt">
        <p><b>下单抽奖：</b>{{ orderDetailsData.cprc || '0' }}</p>
      </div>
    </ng-template>
  </div>
</nz-card>
<!-- 机器评估详情 END -->

<!-- 机器验机详情 START -->
<nz-card [nzSize]="cardSize" class="m-b-2">
  <div class="card-p">
    <p>
      机器验机详情
      <span class="result-sp p-l-10">
        当前订单有 {{ orderDetailsData?.sfPackageNumber || '0' }} 个包裹，请注意

        <button
          nz-button
          nzType="link"
          nzSize="small"
          class="m-r-10"
          (click)="showMakeupModal()"
        >加价设置</button>

        <!-- 加价设置 Modal -->
        <makeup-setup-modal
          [(ngModel)]="makeupVisible"
          [otherParams]="{
            id: orderDetailsData?.id,
            userId: orderDetailsData?.userId
          }"
          [setupDisabled]="!machineDetailsTable?.length || ![15, 18, 21].includes(orderDetailsData?.ostat)"
          (submitSetup)="submitSetupCoupon($event)"
        ></makeup-setup-modal>

        <button
          *ngIf="permission.userPermission.has('aisiRecyc:loveOrderManage:editDetails') && [15, 16, 18].includes(orderDetailsData?.ostat)"
          nz-button
          nzType="primary"
          nzDanger
          nzSize="small"
          [disabled]="orderDetailsData?.isActivation == 1"
          (click)="showEditDetailsModal()"
        >修改验机详情</button>
      </span>
    </p>
    <button nz-button nzType="link" (click)="setPrint()">设置打印机</button>
  </div>

  <div class="table-test">
    <nz-table
      #basicTable
      nzSize="small"
      nzBordered
      [nzFrontPagination]="false"
      [nzShowPagination]="false"
      [nzData]="machineDetailsTable">
      <thead>
        <tr>
          <th nzAlign="center">机器编号</th>
          <th nzAlign="center">机器型号</th>
          <th nzAlign="center">验机状态</th>
          <th nzAlign="center">验机价</th>
          <th nzAlign="center">加价金额</th>
          <th nzAlign="center">更新时间</th>
          <th nzAlign="center">操作</th>
        </tr>
      </thead>
      <tbody>
        <ng-container *ngFor="let data of basicTable.data">
          <tr>
            <td nzAlign="center">{{ data.phoneCode || '-' }}</td>
            <td nzAlign="center">{{ data.modelName || '-' }}</td>
            <td nzAlign="center">{{ data.status | machineInspectionStatus }}</td>
            <td nzAlign="center">{{ data.price || '0' }}</td>
            <td nzAlign="center">{{ data.aprc || '-' }}</td>
            <td nzAlign="center">{{ data.updateTime || '-' }}</td>
            <td nzAlign="center">
              <a nz-button nzType="link" target="_blank" [routerLink]="['/used-store/usedDeviceList']" [queryParams]="{ code: data.phoneCode }">查看机器信息</a>
              <button nz-button nzType="link" (click)="print(data)">打印标签</button>
              <button nz-button nzType="link" (click)="jumpReport(2, data)" *ngIf="[3, 5].includes(data.status)">编辑验机报告</button>
              <button nz-button nzType="link" (click)="showReportModal(data)" *ngIf="data.status == 3">查看验机报告</button>
              <button nz-button nzType="link" (click)="jumpReport(1, data)" [hidden]="!([1, 2, 4].includes(data.status))">继续验机</button>
              <a
                [disabled]="orderDetailsData?.isPush == 1 || [3, 5].includes(data.status) || [22].includes(orderDetailsData.ostat)"
                nz-button
                nzType="link"
                nzDanger
                nz-popconfirm
                nzPopconfirmTitle="确认删除?"
                (nzOnConfirm)="deleteTestMachine(data)"
              >
                删除
              </a>
            </td>
          </tr>
        </ng-container>
        <tr [hidden]="!permission.userPermission.has('aisi-recyc:loveOrderManage:addMachine') || orderDetailsData?.isPush == 1 || [15,16,18,19,20,22,23,24,25,91].includes(orderDetailsData.ostat)">
          <td nzAlign="center" colSpan="7">
            <button nz-button nzType="link" (click)="jumpReport(0)">
              <i nz-icon nzType="plus" nzTheme="outline"></i>添加机器
            </button>
          </td>
        </tr>
      </tbody>
    </nz-table>
  </div>

  <div class="sum-ul" *ngIf="machineDetailsTable.length">
    <p class="sum-p">验机总价：{{ machineReduce(machineDetailsTable) }}</p>
    <p class="sum-p" *ngIf="orderDetailsData?.couponName && orderDetailsData?.aprc">
      {{ orderDetailsData?.couponName }}：{{ machineMakeupSum() }}
    </p>
    <p class="sum-p">下单抽奖：{{ orderDetailsData.cprc || '0' }}</p>
    <p class="sum-p">验机合计：<b>{{ machineReduce(machineDetailsTable) + machineMakeupSum() + (orderDetailsData.cprc || 0) }}</b></p>
  </div>

  <div class="test-foot" *ngIf="machineDetailsTable.length">
    <span *ngIf="orderDetailsData?.isPush == 1" class="report-tips p-r-20">验机报告已推送</span>
    <button
      nz-button
      nzType="primary"
      [disabled]="orderDetailsData?.isPush == 1"
      (click)="showConfirm()"
    >推送验机报告</button>
  </div>
</nz-card>
<!-- 机器验机详情 END -->

<!-- 跟进记录 START -->
<nz-card [nzSize]="cardSize">
  <p class="card-p">
    跟进记录
    <button nz-button nzType="link" (click)="showFollowModal()">跟进</button>
  </p>

  <div class="follow-table">
    <nz-table
      #followTable
      nzSize="small"
      nzBordered
      nzHideOnSinglePage
      nzShowQuickJumper
      nzShowSizeChanger
      [nzShowPagination]="true"
      [nzData]="followTableData">
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="120px">ID</th>
          <th nzAlign="center" nzWidth="150px">跟进人</th>
          <th nzAlign="center" nzWidth="180px">跟进时间</th>
          <th nzAlign="center">跟进内容</th>
          <th nzAlign="center">备注</th>
        </tr>
      </thead>
      <tbody>
        <tr *ngFor="let data of followTable.data">
          <td nzAlign="center">{{ data.id }}</td>
          <td nzAlign="center">{{ data.follower || '-' }}</td>
          <td nzAlign="center">{{ data.createTime || '-' }}</td>
          <td nzAlign="center">{{ data.content || '-' }}</td>
          <td nzAlign="center">{{ data.remarks || '-' }}</td>
      </tbody>
    </nz-table>
  </div>
</nz-card>
<!-- 跟进记录 END -->

<!-- 评估详情 -->
<assessment-details-modal #detailRef [optionParams]="previewParams"></assessment-details-modal>

<!-- 添加跟进 START -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isFollowVisible"
  nzTitle="跟进"
  (nzOnCancel)="followCancel()">

  <div *nzModalContent>
    <div class="custom-model-body">
      <!-- body START -->
      <form nz-form class="form-modal-body" [formGroup]="followForm">
        <nz-form-item>
          <nz-form-label nzSpan="5" nzRequired>备注</nz-form-label>
          <nz-form-control nzSpan="19" nzErrorTip="请输入跟进内容!">
            <nz-textarea-count [nzMaxCharacterCount]="150">
              <textarea rows="4" maxlength="150" formControlName="remarks" nz-input placeholder="请输入跟进内容（必填）"></textarea>
            </nz-textarea-count>
          </nz-form-control>
        </nz-form-item>
      </form>
      <!-- body END -->
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="primary" (click)="submitFollow()">确定</button>
        <button nz-button nzType="default" (click)="followCancel()">取消</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- 添加跟进 END -->

<!-- 异常Modal START -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isAbnormalVisible"
  nzTitle="物品异常"
  (nzOnCancel)="handleCancel()">

  <div *nzModalContent>
    <div class="custom-model-body">
      <!-- body START -->
      <form nz-form class="form-modal-body" [formGroup]="abnormalForm">
        <nz-form-item>
          <nz-form-label nzSpan="7" nzRequired>异常类型</nz-form-label>
          <nz-form-control nzSpan="17" nzErrorTip="请选择异常类型!">
            <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择异常类型" formControlName="type">
              <nz-option nzLabel="Jack" nzValue="jack"></nz-option>
              <nz-option nzLabel="Lucy" nzValue="lucy"></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzSpan="7" nzRequired>是否需退回</nz-form-label>
          <nz-form-control nzSpan="17" nzErrorTip="请选择是否需退回!">
            <nz-radio-group formControlName="isReturn">
              <label nz-radio nzValue="A">是</label>
              <label nz-radio nzValue="B">B</label>
            </nz-radio-group>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzSpan="7" nzRequired>入库库位</nz-form-label>
          <nz-form-control nzSpan="17" nzErrorTip="请输入跟进内容!">
            <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择入库库位" formControlName="location">
              <nz-option nzLabel="Jack" nzValue="jack"></nz-option>
              <nz-option nzLabel="Lucy" nzValue="lucy"></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>
      </form>
      <!-- body END -->
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="primary" (click)="submitForm()">确定</button>
        <button nz-button nzType="default" (click)="handleCancel()">取消</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- 异常Modal END -->

<!-- 打印标签 -->
<app-print-device-info [hidden]="true" [deviceInfo]="deviceInfo" id="printDeviceInfo"></app-print-device-info>

<!-- S 验机报告 -->
<machine-report-modal #reportModalRef></machine-report-modal>
<!-- E 验机报告 -->

<!-- S 修改验机详情 -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isEditDetailsVisible"
  [nzTitle]="'修改验机详情'"
  (nzOnCancel)="isEditDetailsVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <p class="edit-details-tip">是否要允许修改验机详情?</p>

      <nz-form-item>
        <nz-form-label [nzSpan]="4" nzRequired>备注</nz-form-label>
        <nz-form-control [nzSpan]="20">
          <nz-textarea-count [nzMaxCharacterCount]="200">
            <textarea
              rows="4"
              nz-input
              maxlength="200"
              placeholder="请输入原因"
              [(ngModel)]="editDetailsText"
            ></textarea>
          </nz-textarea-count>
        </nz-form-control>
      </nz-form-item >
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="default" (click)="isEditDetailsVisible = false">取消</button>
        <button nz-button nzType="primary" [nzLoading]="subEditDetailsLoading" (click)="subEditDetailsData()">确定</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- E 修改验机详情 -->
